// api.js - API 接口定义
// 注意：只包含后端已实现的接口

import request from './request';

/**
 * 用户相关 API
 */
export const userApi = {
  // 登录
  login: (phone, password) => {
    return request.post('/users/loginByPhoneAndPassword', { phone, password });
  }
};

/**
 * 课程相关 API
 */
export const courseApi = {
  // 创建课程
  createCourse: (data) => {
    return request.post('/course/createCourse', data);
  },

  // 更新课程信息（上传完文件后调用）
  updateCourse: (insertId, course) => {
    return request.post('/course/updateCourse', { insertId, course });
  },

  // 根据课程ID获取课程详情
  getCourseById: (courseId) => {
    return request.post('/course/getCourseById', { courseId });
  },

  // 获取教师课程列表
  getTeacherCoursesList: (phone) => {
    return request.post('/course/getTeacherCoursesList', { phone });
  },

  // 管理员可以查询所有的课程列表
  getAdminCoursesList: () => {
    return request.post('/course/getAllCoursesList');
  },

  // 根据id删除课程
  removeCourseById: (courseId) => {
    return request.post('/course/removeCourseById', { id: courseId });
  },

  // 添加学员到课程
  addStudentToCourse: (courseId, studentPhone) => {
    return request.post('/course/addStudentToCourse', { courseId, studentPhone });
  }
};

/**
 * 案例相关 API
 */
export const caseApi = {
  // 根据教师手机号获取案例列表
  getCasesByTeacherPhone: (teacherPhone) => {
    return request.post('/case/getCasesByTeacherPhone', { teacherPhone });
  },

  // 添加案例
  addCase: (caseData) => {
    return request.post('/case/addCase', {caseData: caseData});
  },

  // 根据案例ID获取案例详情
  getCaseById: (caseId) => {
    return request.post('/case/getCaseById', { caseId });
  },

  // 编辑案例
  editCaseById: (caseId, caseTitle, caseContent, caseImages) => {
    return request.post('/case/editCaseById', { caseId, caseTitle, caseContent, caseImages });
  },

  // 根据id删除案例
  removeCaseById: (caseId) => {
    return request.post('/case/removeCaseById', { caseId: caseId });
  }
};

/**
 * 导出所有 API
 */
export default {
  user: userApi,
  course: courseApi,
  case: caseApi
};
